<template>
  <div>
    <!-- 结构 -->
    <el-container class="my-layout">
      <el-aside width="200px">
        <img width="100%" src="@/assets/images/logo.png" alt="">

        <!-- el-menu 导航菜单，默认垂直排列 -->
        <el-menu :default-active="$route.path" background-color="#023" text-color="#fff" active-text-color="#409EFF"
          style="border-right: none;" router>

          <!-- el-menu-item 菜单项 -->
          <el-menu-item index="/">
            <!-- el-icon-xx   element-ui 内置图标 -->
            <i class="el-icon-s-home"></i> 数据概览
          </el-menu-item>

          <el-menu-item index="/article">
            <i class="el-icon-document"></i> 内容管理
          </el-menu-item>

          <el-menu-item index="/publish">
            <i class="el-icon-s-promotion"></i> 发布文章
          </el-menu-item>

          <el-menu-item index="/newhome">
            <i class="el-icon-s-promotion"></i> 个人中心
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <span>{{ user.name || user.monile }}</span>
          <el-link @click="ondel()" :underline="false" icon="el-icon-unlock">退出</el-link>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import auth from '@/utils/token'
export default {
  // 行为
  name: 'LayouTt',
  data () {
    return {
      user: {}
    }
  },
  async created () {
    // 在拦截器中自动拼接token
    const res = await this.$http.get('/v1_0/user/profile')
    console.log(res)

    this.user = res.data.data
  },
  methods: {
    ondel () {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 删除token
        auth.removeToken()
        // 跳转登录页面
        this.$router.push('/login')
        // 提示
        this.$message({})
      }).catch(() => {

      })
    }
  }
}
</script>
<style scoped>
.my-layout {
    /* 1vw 视口宽度的 1% */
    /* 1vh 视口高度的 1% */
    height: 100vh;
}

.el-aside {
    background-color: #023;
}

.el-header {
    border-bottom: 1px solid #ddd;
}
.el-header{
    display: flex;
    justify-content: end;
    align-items: center;
    gap:10px
}
</style>
